package com.itms.tool.utils;

import com.itms.tool.R;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Checkable;
import android.widget.TextView;

public class CheckableTextView extends TextView implements Checkable {

	private boolean mChecked;
	private int mCheckedResId;
	private int mNormalResId;
	
	public CheckableTextView(Context context) {
		this(context, null);
	}
	
	public CheckableTextView(Context context, AttributeSet attrs) {
		this(context, attrs, R.drawable.tv_bg_checked, R.drawable.tv_bg_normal);
	}

	public CheckableTextView(Context context, AttributeSet attrs, int checkedResId, int normalResId) {
		super(context, attrs);
		mCheckedResId = checkedResId;
		mNormalResId = normalResId;
	}
	
	public void setCheckedResourceId(int resId) {
		mCheckedResId = resId;
		setChecked(mChecked);
	}
	
	public void setNormalResourceId(int resId) {
		mNormalResId = resId;
		setChecked(mChecked);
	}
	
	@Override
	public void setChecked(boolean checked) {
		mChecked = checked;
		if (mChecked) {
			setBackgroundResource(mCheckedResId);
		} else {
			setBackgroundResource(mNormalResId);
		}
	}

	@Override
	public boolean isChecked() {
		return mChecked;
	}

	@Override
	public void toggle() {
		setChecked(!mChecked);
	}

}
